package org.jeecg.modules.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.business.entity.BusMarketCoupons;
import org.jeecg.modules.business.entity.BusMarketCouponsCash;
import org.jeecg.modules.business.entity.BusMarketCouponsCashUsed;
import org.jeecg.modules.business.entity.BusMarketCouponsUsed;
import org.jeecg.modules.business.mapper.BusMarketCouponsCashMapper;
import org.jeecg.modules.business.mapper.BusMarketCouponsMapper;
import org.jeecg.modules.business.service.IBusMarketCouponsCashService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @Description: bus_market_coupons_cash_info
 * @Author: jeecg-boot
 * @Date:   2023-03-03
 * @Version: V1.0
 */
@Service
public class BusMarketCouponsCashServiceImpl extends ServiceImpl<BusMarketCouponsCashMapper, BusMarketCouponsCash> implements IBusMarketCouponsCashService {
    @Resource
    private BusMarketCouponsCashMapper busMarketCouponsCashMapper;
    @Resource
    private BusMarketCouponsCashUsedServiceImpl busMarketCouponsCashUsedService;

    public Page<BusMarketCouponsCash> pageList(Page<BusMarketCouponsCash> page, BusMarketCouponsCash model) {
        return page.setRecords(busMarketCouponsCashMapper.getCouponsCashList(page, model));
    }

    /**
     * 删除活动及其券记录
     * @param id
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public Result removeCouponsAndCouponsUsedById(String id) {
        this.removeById(id);
        LambdaQueryWrapper<BusMarketCouponsCashUsed> queryWrapper = new LambdaQueryWrapper<BusMarketCouponsCashUsed>().eq(BusMarketCouponsCashUsed::getCouponsId, id);
        busMarketCouponsCashUsedService.remove(queryWrapper);
        return Result.ok("删除成功!");
    }
}
